//
//  Globle.m
//  TBRJL
//
//  Created by 程三 on 15/6/13.
//  Copyright (c) 2015年 程三. All rights reserved.
//

#import "Globle.h"
#import "AppDelegate.h"
#import "Util.h"

#define USERINFOKEY    @"userInfoKey"
#define SERVICEURLKEY  @"serviceURLKey"
#define UPDATEURLKEY   @"updateURLKey"
#define USERNAMEKEY    @"userNameKey"
#define PASSWORDKEY    @"passWordKey"



static Globle *globle;
@implementation Globle

-(id)init
{
    self = [super init];
    if(self)
    {
        //单例重建，获取单例中的信息
        _userInfoDic = (NSDictionary *)[Util getValue:USERINFOKEY];
        _serviceURL = (NSString *)[Util getValue:SERVICEURLKEY];
        _updateURL = (NSString *)[Util getValue:UPDATEURLKEY];
        _userName = (NSString *)[Util getValue:USERNAMEKEY];
        _passWord = (NSString *)[Util getValue:PASSWORDKEY];
        _user = (NSString *)[Util getValue:@"user"];
        _key = (NSString *)[Util getValue:@"key"];
        //创建调用服务接口对象
        _service = [[AFNetWorkService alloc] init];
    }
    
    return  self;
}

#pragma mark 获取单例
+(Globle *)getInstance
{
    static dispatch_once_t once;
    dispatch_once(&once, ^{
        if (!globle)
        {
            globle = [[Globle alloc] init];
        }
    });
    
    return globle;
}

#pragma mark 设置用户信息
-(void)setUserInfoDic:(NSDictionary *)userInfoDic
{
    _userInfoDic = userInfoDic;
    //保存到本地
    [Util setObject:userInfoDic key:USERINFOKEY];
}

#pragma mark 设置URL
-(void)setServiceURL:(NSString *)serviceURL
{
    _serviceURL = serviceURL;
    [Util setObject:serviceURL key:SERVICEURLKEY];
}

#pragma mark 设置updateURL
-(void)setUpdateURL:(NSString *)updateURL
{
    _updateURL = updateURL;
    [Util setObject:updateURL key:UPDATEURLKEY];
}

#pragma mark 设置用户名
-(void)setUserName:(NSString *)userName
{
    _userName = userName;
    [Util setObject:userName key:USERNAMEKEY];
}

#pragma mark 设置密码
-(void)setPassWord:(NSString *)passWord
{
    _passWord = passWord;
    [Util setObject:passWord key:PASSWORDKEY];
}

-(void)setUser:(NSString *)user{
    _user = user;
    [Util setObject:user key:@"user"];
}

-(void)setKey:(NSString *)key{
    _key = key;
    [Util setObject:key key:@"key"];
}
@end
